package org.hot100_5.leetcode21;

import org.leetcode.easy.ListNode;

import java.util.List;

public class Solution {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {

        ListNode dummy = new ListNode(-1);

        ListNode temp = dummy;

        while (list1!=null && list2!=null){
            if (list1.val<list2.val){
                temp.next = list1;
                list1= list1.next;
            }else {
                temp.next = list2;
                list2= list2.next;
            }
                temp = temp.next;
        }

        if (list1==null){
            temp.next = list2;
        }

        if (list2==null){
            temp.next = list1;
        }

        return dummy.next;
    }
}
